/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.ItemAuthorsDAO;
import cms.exceptions.HibernateAccessLayerException;

import dto.Itemauthors;
import java.util.List;

/**
 *
 * @author eichawsan
 */
public class ItemAuthorsDAOImpl extends AbstractDAO implements ItemAuthorsDAO{

     public ItemAuthorsDAOImpl(){
         super();
     }

    @Override
    public List<Itemauthors> findAllItemauthors() throws HibernateAccessLayerException {
        try {
            List result= super.findAll(Itemauthors.class);
            return (result);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        
    }
    
    @Override
    public void insertItemauthors(Itemauthors itemauthor) throws HibernateAccessLayerException {
        try {
            super.saveOrUpdate(itemauthor);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
     @Override
    public void updateItemauthors(Itemauthors itemauthor) throws HibernateAccessLayerException {
         try {
            super.saveOrUpdate(itemauthor);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }
     @Override
    public void deleteItemauthors(Itemauthors itemauthor) throws HibernateAccessLayerException {
        try {
            super.delete(itemauthor);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public  List<Itemauthors> findItemauthorsByConferenceName(String conferenceName) throws HibernateAccessLayerException {
       try {
            return  (List<Itemauthors>)
                    this.findByCustomizeQuery(Itemauthors.class, "conferenceName='"+conferenceName+"'");
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public  List<Itemauthors> findItemauthorsByItemName(String itemName) throws HibernateAccessLayerException {
         try {
            return  (List<Itemauthors>)
                    this.findByCustomizeQuery(Itemauthors.class, "itemName='"+itemName+"'");
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
    @Override
     public  Itemauthors  findItemauthors(String conferenceName,String itemName,String authorsName) throws HibernateAccessLayerException {
      try {
            return  ((List<Itemauthors>)
                    this.findByCustomizeQuery(Itemauthors.class,  "conferenceName='"+conferenceName+"' and itemName='"+itemName+"' and userName='"+authorsName+"'")).get(0);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }

    @Override
    public List<Itemauthors> findItemauthorsByAuthoerName(String authorsName) throws HibernateAccessLayerException {
        try {
            return  (List<Itemauthors>)
                    this.findByCustomizeQuery(Itemauthors.class,  "userName='"+authorsName+"'");
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
    
    @Override
    public List<Itemauthors> findByCustomizeQuery(String queryString) throws HibernateAccessLayerException {
        return  (List<Itemauthors>)(this.findByCustomizeQuery(Itemauthors.class,queryString));
    }

}
